package com.rdc.qingkou.dto;


import android.util.Log;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;
import com.rdc.qingkou.entity.User;
import com.rdc.qingkou.utils.MyUtils;
import com.rdc.qingkou.vo.CommentOneLevelVO;
import com.rdc.qingkou.vo.CommentTwoLevelVO;
import com.rdc.qingkou.vo.UserVO;

import java.util.ArrayList;
import java.util.List;

public class CommentDTO {

    public String result;
    public List<Comment> message;

    public static class Comment {
        public int commentId;
        public User user;
        public String content;
        public int parentCommentId;
        public int praiseNumber;
        public int commentsNumber;
        public User Reviewer;  //被评论者
        public boolean isPraise;  //对于当前用户是否已经点赞
        public String commentDate;


        CommentOneLevelVO transformToOneLevel() {
            CommentOneLevelVO comment = new CommentOneLevelVO();
            comment.setCommentId(commentId);
            if (commentDate != null) {
                comment.setCommentDate(commentDate);
            } else {
                comment.setCommentDate("未知");
            }
            comment.setCommentsNumber(commentsNumber);
            comment.setContent(content.replace("\"", ""));
            comment.setPraise(isPraise);
            comment.setPraiseNumber(praiseNumber);
            UserVO u = new UserVO();
            if (user.getNickName() == null || user.getNickName().equals("")) {
                u.setNickName("名字为空！");
            } else {
                u.setNickName(user.getNickName().replace("\"", ""));
            }
            u.setUserId(user.getUserId());
            if (user.getImageUrl() != null && !user.getImageUrl().equals("")) {
                u.setHeadImageUrl("http://120.78.74.103" + user.getImageUrl());
            } else {
                u.setHeadImageUrl(MyUtils.getUriFromDrawableRes(MyApplication.getContext(), R.drawable.pic6));
            }
            if (user.getSignature() != null) {
                u.setSignature(user.getSignature().replace("\"", ""));
            }
            u.setSubsribeStatus(false);
            comment.setUser(u);
            return comment;
        }


        CommentTwoLevelVO transformToTwoLevel() {
            CommentTwoLevelVO comment = new CommentTwoLevelVO();
            comment.setCommentId(commentId);
            comment.setCommentDate(commentDate);
            comment.setCommentsNumber(commentsNumber);
            comment.setContent(content);
            comment.setPraise(isPraise);
            comment.setPraiseNumber(praiseNumber);
            UserVO u = new UserVO();
            if (user.getNickName() == null || user.getNickName().equals("")) {
                u.setNickName("路人甲");
            } else {
                u.setNickName(user.getNickName().replace("\"", ""));
            }
            u.setUserId(user.getUserId());
            if (user.getImageUrl() != null && !user.getImageUrl().equals("")) {
                u.setHeadImageUrl("http://120.78.74.103" + user.getImageUrl());
            } else {
                u.setHeadImageUrl(MyUtils.getUriFromDrawableRes(MyApplication.getContext(), R.drawable.pic6));
            }
            if (user.getSignature() != null) {
                u.setSignature(user.getSignature().replace("\"", ""));
            }
            u.setSubsribeStatus(false);
            comment.setUser(u);

            if (Reviewer != null) {
                UserVO reviewer = new UserVO();
                if (Reviewer.getNickName() == null || Reviewer.getNickName().equals("")) {
                    reviewer.setNickName("名字为空！");
                } else {
                    reviewer.setNickName(Reviewer.getNickName().replace("\"", ""));
                }
                reviewer.setUserId(Reviewer.getUserId());
                if (Reviewer.getImageUrl() != null && !Reviewer.getImageUrl().equals("")) {
                    Log.d("LYT", "transformToTwoLevel: " + Reviewer.getImageUrl());
                    reviewer.setHeadImageUrl("http://120.78.74.103" + Reviewer.getImageUrl());
                } else {
                    reviewer.setHeadImageUrl(MyUtils.getUriFromDrawableRes(MyApplication.getContext(), R.drawable.pic6));
                }
                if (Reviewer.getSignature() != null) {
                    reviewer.setSignature(Reviewer.getSignature().replace("\"", ""));
                }
                reviewer.setSubsribeStatus(false);
                comment.setReviewer(reviewer);
            } else {
                comment.setReviewer(null);
            }
            comment.setParentCommentId(parentCommentId);
            return comment;
        }
    }

    public List<CommentTwoLevelVO> transformToTwoLevel() {
        List<CommentTwoLevelVO> list = new ArrayList<>();
        for (Comment comment : message) {
            list.add(comment.transformToTwoLevel());
        }
        return list;
    }

    public List<CommentOneLevelVO> transformToOneLevel() {
        List<CommentOneLevelVO> list = new ArrayList<>();
        for (Comment comment : message) {
            list.add(comment.transformToOneLevel());
        }
        return list;
    }


}
